package com.hs;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

/**
 * @author hs
 * 测试 信号量 限流
 */
public class SemaphoreTest {
    private static final int MAX_AVAILABLE = 5;


    public static void main(String[] args) throws InterruptedException {
        Semaphore available = new Semaphore(MAX_AVAILABLE, true);

        for(int i = 0;i<10;i++){
            //available.acquire();
            available.tryAcquire(2000, TimeUnit.MICROSECONDS);
            System.out.println(i);
            //available.release();
        }


    }

}
